/*子页面需要填写的内容：*/
function child(room_id){
	
	var id= room_id;
	$("#room_id").val(id);
	roominfo();
	

	
	
//该方法相当于入口函数，进入该子页面即执行
}

function addRoom(){
	$.ajax({
		url:"../../room/add",
		type:"post",
		dataType:"json",
		data:{
			roomnum:$("#roomnum").val(),
			roomtype_id:$("#roomtype_id").val(),
			location:$("#location").val(),
			phone:$("#phone").val(),
			status:$("#status").val()
			
		},
		success:function(data){
			if(data==0){
				alert("添加失败");
				parent.layer.closeAll();//关闭所有的弹窗
				 parent.location.reload();
			}else{
				
				parent.layer.closeAll();//关闭所有的弹窗
				 parent.location.reload();
			}
			
			
		}

		
		
		
	});
	
	
	
	
	
}


function loadRoomTypeSelect(){
	$.ajax({
		url:"../../roomtype/all",
		type:"get",
		dataType:"json",
		success:function(data){
			//为房间类型添加选项
			var selectItems = "";
			selectItems += '<option value="0"></option></br>';
			for (var i = 0; i < data.length; i++) {
				var roomtype = data[i];
				
				selectItems += '<option value="'+roomtype.roomtype_id+'">'+roomtype.type+'</option></br>';
				
				
			}
			
			$("#roomtype_id").html(selectItems);
		}

		
		
		
	});
}
loadRoomTypeSelect()

function checkRoomNum(){
//	var roomnum = $("#roomnum").val();
	$.ajax({
		url:"../../room/check",
		type:"post",
		dataType:"json",
		data:{
			roomnum:$("#roomnum").val()
		},
		success:function(data){
			if(data==0){
				$("#error").html('&nbsp;');
			}else{
				$("#error").text("房间号已存在");
			}
			
		}

		
		
		
	});
	
}



function roominfo(){
	$.ajax({
		url:"../../room/roominfo",
		type:"post",
		dataType:"json",
		data:{
			room_id:$("#room_id").val()
		},
		success:function(data){
			$("#roomnum").val(data.roomnum);
			$("#location").val(data.location);
			$("#phone").val(data.phone);
			$("#roomtype_id option[value='"+data.roomtype_id+"']").attr("selected", true);
			$("#status option[value='"+data.status+"']").attr("selected", true);
			
		}

		
		
		
	});
}

function updateRoom(){
	$.ajax({
		url:"../../room/update",
		type:"post",
		dataType:"json",
		data:{
			room_id:$("#room_id").val(),
			roomnum:$("#roomnum").val(),
			roomtype_id:$("#roomtype_id").val(),
			location:$("#location").val(),
			phone:$("#phone").val(),
			status:$("#status").val()
			
		},
		success:function(data){
			if(data==0){
				alert("修改失败");
				parent.layer.closeAll();//关闭所有的弹窗
				 parent.location.reload();
			}else{
				
				parent.layer.closeAll();//关闭所有的弹窗
				 parent.location.reload();
			}
			
			
		}

		
		
		
	});
	
}

